<template>
	<view>
		<u-navbar title="我的车辆">

		</u-navbar>
		<formz ref="formz" :inputs="inputs" :data="data"></formz>
		<bottombox>

			<u-button type="error" :loading="loading" text="保存" @click="save"></u-button>
		</bottombox>
	</view>
</template>

<script>
	import {
		getPage,
		getupdate
	} from "@/api/workerManagement.js"

	import {
		getPage as getPagecx
	} from "@/api/vehicleManagement"
	export default {
		data() {
			return {
				loading: false,
				inputs: [],
				data: {},
				csoption: []
			}
		},
		created() {
			this.init()
		},
		methods: {
			async init() {
				let data = await getPage({
					id: this.$store.state.user.user.sjdata.id
				})
				this.data = data.data.records[0] || {}
				let cxlist = await getPagecx({
					state: 1
				});
				let option = cxlist.data.records.map(e => {
					return {
						label: e.vehicleTypeName,
						value: String(e.id)
					}
				})
				this.csoption = option;
				this.inputs = [{
						label: "车型",
						value: "vehicleTypeId",
						type: 'select',
						option: option
					},
					{
						label: "车牌号",
						value: "plateNumber"
					},
				]
				console.log(option);
			},
			async save() {
				let data = await this.$refs.formz.validate();
				let dqoptions = this.csoption.find(e => {
					return e.value == data.vehicleTypeId
				})
				data = {
					...data,
					vehicleTypeId: dqoptions.value,
					vehicleTypeName: dqoptions.label
				}
				this.loading = true;
				let par = await getupdate(data)
				this.loading = false;
				uni.navigateBack()
				// console.log(par);
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>